//
//  SJXQHeaderTitleView.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/11.
//  Copyright © 2019 李文强. All rights reserved.
//

#import "SJXQHeaderTitleView.h"

@implementation SJXQHeaderTitleView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame andArray:(NSArray *)array{
    if ([super initWithFrame:frame]) {
        _dataArray = array;
        [self initSubView];
    }
    return self;
}
- (void)initSubView{
//    __weak typeof(self)weakSelf = self;
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    UILabel * contLab = [UILabel new];
        CGFloat W = 1.0/_dataArray.count;
        for (int i = 0; i<_dataArray.count; i++){
            UILabel *label = [[UILabel alloc] init];
            label.frame = CGRectMake(W*i,0,W,44);
            label.numberOfLines = 0;
            label.textAlignment = 1;
            label.text = _dataArray[i];
            label.tag = 30+i;
            label.font = [UIFont systemFontOfSize:14];
            label.textColor = [UIColor darkGrayColor];
            [self addSubview:label];
            if (i == 0) {
                contLab = label;
                [label mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(@0);
                    make.centerY.equalTo(self.mas_centerY);
                    make.width.equalTo(self).multipliedBy(W);
                    make.height.mas_equalTo(40);
                }];
            } else {
                [label mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(contLab.mas_right);
                    make.centerY.equalTo(self.mas_centerY);
                    make.width.equalTo(self).multipliedBy(W);
                    make.height.mas_equalTo(40);
                }];
                contLab = label;
            }
        }
//    });
    
}
- (void)reloadView:(NSArray *)option{
    for (int i = 0; i<option.count; i++){
        UILabel *label = (UILabel *)[self viewWithTag:30+i];
        label.text = option[i];
    }
}
@end
